package com.dataaccess.dataaccess.web.web;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseController;
import com.dataaccess.dataaccess.model.AlarmAllDeviceDataChanged;
import com.dataaccess.dataaccess.support.annotaion.Action;
import com.dataaccess.dataaccess.support.annotaion.At;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.web.mapper.AlarmAllDeviceDataChangedMapper;
import com.dataaccess.dataaccess.web.service.TemperatureAndHumidityService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author: YangYu
 * @ClassName: TemperatureAndHumidityController
 * @Date: Created in 09:35 2023/11/30
 * @Description: 温湿度
 */
@Action
@RequestMapping("temperatureAndHumidity")
public class TemperatureAndHumidityController extends BaseController {

    @Resource
    public MyLogger logger;
    @Resource
    private AlarmAllDeviceDataChangedMapper alarmAllDeviceDataChangedMapper;
    @Resource
    private TemperatureAndHumidityService temperatureAndHumidityService;

    /**
     * @Author YangYu
     * @Description 山东123物联网（温湿度T20）
     * @Date Created in 09:32 2023/11/30
     * @Param [jsonParam]
     */

    @At(value = "device/T20", method = RequestMethod.POST)
    public RespEntity deviceDataChanged(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("T20"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("T20");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        return temperatureAndHumidityService.t20(jsonParam);
    }

}
